import type { CustomColumnOptions, TableMethods } from '@/types/table';
import { ReactNode } from 'react';

// 常用的字段配置模板
export const commonFieldConfigs = {
  // 文本字段
  text: (
    fieldName: string,
    options?: {
      width?: number;
      ellipsis?: boolean;
      align?: 'left' | 'center' | 'right';
    },
  ) => ({
    [fieldName]: {
      width: options?.width || 120,
      ellipsis: options?.ellipsis || true,
      align: options?.align || 'left',
    },
  }),

  // 操作字段
  operate: (
    methods?: TableMethods,
    options?: {
      width?: number;
      fixed?: 'left' | 'right';
    },
  ) => ({
    operate: {
      width: options?.width || 150,
      fixed: options?.fixed || 'right',
      render: (text: ReactNode, record: any) => {
        console.log('operate', record);
        return null;
      },
    },
  }),
};

// 合并多个字段配置
export const mergeFieldConfigs = (...configs: CustomColumnOptions[]): CustomColumnOptions => {
  return configs.reduce((merged, config) => ({ ...merged, ...config }), {});
};
